﻿using ET.DBCommon.Model;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ET.DBCommon.DAL
{
    public class TestPaperManageDAL
    {
        public static TestPaperManageModel GetUpdateExamData(int TestQuestionID)
        {
            TestPaperManageModel testPaperManageModel = new TestPaperManageModel();
            string sql = "select * from testpapermanage where TestQuestionId={0}";
            sql = string.Format(sql, TestQuestionID);
            DataSet ds = DbHelper.ExecuteDataset(sql);
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                DataTable dt = ds.Tables[0];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    testPaperManageModel.TestQuestionID = Convert.ToInt32(dt.Rows[i]["TestQuestionId"].ToString());
                    testPaperManageModel.FaultType = dt.Rows[i]["FaultType"].ToString();
                    testPaperManageModel.LogicID = Convert.ToInt32(dt.Rows[i]["LogicID"].ToString());
                    testPaperManageModel.OrderNumber = dt.Rows[i]["OrderNumber"].ToString() == "" ? 0 : Convert.ToInt32(dt.Rows[i]["OrderNumber"].ToString()); 
                    testPaperManageModel.DownOrderNumber = dt.Rows[i]["DownOrderNumber"].ToString()==""?0:Convert.ToInt32(dt.Rows[i]["DownOrderNumber"].ToString());
                    return testPaperManageModel;
                }
            }
            return testPaperManageModel;
        }
        //插入数据 Add by gy
        public static void InsertExamData(int TestQuestionID,string Describes, string FaultType,int LogicID,int OrderNumber,int DownOrderNumber)
        {
            string sql = "insert into testpapermanage(TestQuestionId,`Describes`,FaultType,LogicID,OrderNumber,DownOrderNumber) value('" + TestQuestionID+ "','" + Describes + "','" + FaultType + "','" + LogicID + "','" + OrderNumber + "','" + DownOrderNumber + "')";         
            DbHelper.ExecuteNonQuery(sql);
        }
        //删除数据
        public static bool DeleteExamInfo(int TestQuestionID)
        {
            string sql = "delete from testpapermanage where TestQuestionId =@TestQuestionID";
            MySqlParameter[] parms = {
                new MySqlParameter("@TestQuestionID", TestQuestionID)
            };
            return DbHelper.ExecuteNonQuery(sql, parms) > 0;
        }
        //更新数据
        public static void UpdateExamData(int TestQuestionID, string FaultType, int LogicID, int OrderNumber, int DownOrderNumber)
        {
            string sql = "update testpapermanage set FaultType = @FaultType,LogicID = @LogicID,OrderNumber = @OrderNumber,DownOrderNumber = @DownOrderNumber where TestQuestionId = @TestQuestionId";
            MySqlParameter[] parms =
            {
                new MySqlParameter("@TestQuestionID", TestQuestionID),
                new MySqlParameter("@FaultType", FaultType),
                new MySqlParameter("@LogicID", LogicID),
                new MySqlParameter("@OrderNumber", OrderNumber),
                new MySqlParameter("@DownOrderNumber", DownOrderNumber)
            };
            DbHelper.ExecuteNonQuery(sql, parms);
        }
    }
}
